<?php
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
require_once($GLOBALS['PAD']."Modules/FTK9D4D0/modconf.mex");
MYTCONN(); 

	$qr_String = '';
	
	if ($_POST['OFCountry'] > 0) {
	$qr_String .= ' AND OFCorr = '.$_POST['OFCorr'];
	}
	if ($_POST['OFCorr'] > 0) {
	$qr_String .= ' AND OFCorr = '.$_POST['OFCorr'];
	}
	if ($_POST['OFProv'] > 0) {
	$qr_String .= ' AND OFCorr = '.$_POST['OFCorr'];
	}
	if ($_POST['OFIDCiudad'] > 0) {
	$qr_String .= ' AND OFIDCiudad = '.$_POST['OFIDCiudad'];
	}
	
	$GET = $GLOBALS['MYT']->db_array("SELECT 
						OFId	AS COLID,
						OFCorr	AS COL1,
						OFDelegacion	AS COL3,
						pai_NombreESP	AS COL2,
						Prov_Provincia	AS COL4,
						CiuCiudad	AS COL5,
						OFTelefonos1	AS COL6,
						OFTelefonos2	AS COL7,
						OFActiva	AS COL8
						
				 FROM oficcorresp
						INNER JOIN ciudades ON CiuNumero = OFIDCiudad
						LEFT OUTER JOIN cp_provincias ON ciudades.Prov_ID = cp_provincias.Prov_ID
						INNER JOIN hd_paises ON pai_CodElite = CiuPais
					WHERE OfActiva = 1 {$qr_String}");
	$CCOL = $GET[0];
					?>
<script charset="utf-8" type="text/javascript">
disableSelection(document.getElementById("COAG_Results"))

Ext.onReady(function(){

    Ext.QuickTips.init();

    var myData = [
	<?php   
	for ($i=1;$i<=$CCOL;$i++) { 
	echo "[{$i},'{$GET[$i]['COLID']}','{$GET[$i]['COL1']}','{$GET[$i]['COL2']}','{$GET[$i]['COL3']}','{$GET[$i]['COL4']}','{$GET[$i]['COL5']}','{$GET[$i]['COL6']}','{$GET[$i]['COL7']}','{$GET[$i]['COL8']}']";
		if ($i<$CCOL) {
			echo ',';
		}
    } ?>
    ];

    var ds = new Ext.data.Store({
        reader: new Ext.data.ArrayReader({}, [
               {name: 'id'},
			   {name: 'COLID', type: 'int'},
               {name: 'COL1', type: 'string'},
               {name: 'COL2', type: 'string'},
               {name: 'COL3', type: 'string'},
			   {name: 'COL4', type: 'string'},
               {name: 'COL5', type: 'string'},
               {name: 'COL6', type: 'string'},
               {name: 'COL7', type: 'string'},
               {name: 'COL8', type: 'string'}
          ])
    });
    ds.loadData(myData);
    var colModel = new Ext.grid.ColumnModel([
        {header: "Ordem", width: 75, sortable: true, locked:true, dataIndex: 'COLID'},
        {header: "Correspondente", width: 80, sortable: true, locked:true, dataIndex: 'COL1'},
        {header: "Delegacao", width: 300, sortable: true, dataIndex: 'COL2'},
        {header: "Pais", width: 120, sortable: true, locked:true, dataIndex: 'COL3'},
        {header: "Regiao", width: 75, sortable: true, locked:true, dataIndex: 'COL4'},
        {header: "Cidade", width: 80, sortable: true, locked:true,dataIndex: 'COL5'},
        {header: "Telefone", width: 75, sortable: true, locked:true, align: 'right',dataIndex: 'COL6'},
        {header: "Telefone", width: 75, sortable: true, locked:true, align: 'right',dataIndex: 'COL7'},
        {header: "Activo", width: 75, sortable: true, locked:true,dataIndex: 'COL8'}
    ]);

   var selmode = new Ext.grid.RowSelectionModel({});
   var Console = new Ext.grid.GridPanel({
	    title: 'Agencias Activas',
		layout:'fit',
		ds: ds,
	    cm: colModel,
	    sm: selmode,
		listeners: {
	 				rowdblclick: function(ds, row) { 
					var record = ds.getStore().getAt(row);
  					var value = record.get('COLID');	
					}
				},
	    height: 440,
        renderTo: 'COAG_Results'
    });
		
});
</script>